package com.shoppingmall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shoppingmall.bean.UserInfoBean;
import com.shoppingmall.bean.UserLoginBean;
import com.shoppingmall.dao.RegisterDao;
import com.shoppingmall.service.RegisterService;

/**
 * 用户注册业务逻辑实现
 * @author LIU
 * @version 1.0 2017-11-10
 */
@Service
public class RegisterServiceImpl implements RegisterService {

	@Autowired
	private RegisterDao registerDao;
	
	
	/**
	 * 注册用户
	 * @param userInfo
	 * @param password
	 * @return boolean
	 */
	@Override
	public boolean addUser(UserInfoBean userInfo, String password) {
		// TODO Auto-generated method stub
		boolean result = true;
		try {
			UserLoginBean userLogin = new UserLoginBean();
			userLogin.setPassword(password);
			userLogin.setUsername(userInfo.getUsername());
			registerDao.addUserLogin(userLogin);
			
			userInfo.setUserLoginBean(userLogin);
			registerDao.addUserInfo(userInfo);
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
			throw new IllegalAccessError();
			
		}
		
		return result;
	}

}
